#ifndef QBATTERY_H
#define QBATTERY_H

#include <QDesignerExportWidget>
#include <QWidget>
#include <QColor>
#include <QPaintEvent>

class QDESIGNER_WIDGET_EXPORT QBattery : public QWidget
{
    Q_OBJECT
    Q_PROPERTY(int mPowerLevel READ getPowerLevel WRITE setPowerLevel NOTIFY powerLevelChanged)

private:
    QColor mColorBack = Qt::GlobalColor::white;     //背景色
    QColor mColorBoder = Qt::GlobalColor::black;    //电池边框颜色
    QColor mColorPower = Qt::GlobalColor::green;     //电池颜色
    QColor mColorWarning = Qt::GlobalColor::red;    //电量短缺颜色
    int mPowerLevel = 60;   //电池电量，默认60，范围0-100
    int mWarningLevel = 20;      //电量报警值为20

protected:
    void paintEvent(QPaintEvent *event) override;   //重绘

public:
    explicit QBattery(QWidget *parent = 0);
    void setPowerLevel(int power);  //设置电量
    int getPowerLevel() const;     //获取电量
    void setWaringLevel(int warning);   //设置低电量阈值
    int getWaringLevel() const;     //获取低电量阈值
    QSize getSizeHint() const;      //获取大小

signals:
    void powerLevelChanged(int power);
};

#endif // QBATTERY_H
